<?php
require 'Admin/Controller/Controller.php ';
require 'Admin/Model/CommentsModel.php';

	class CommentsController  extends Controller{
		function __construct(){
			parent::__construct();
		}
		function commentslist(){
			$model=new CommentsModel();
			$data=$model->getCommentsList();
			//return $data;

			$this->assign('comments',$data);
			$this->display();//送到view层显示数据
		}
		function delcomments(){
			$id=$_GET['id'];
			$model= new CommentsModel();
			$result=$model -> delComments($id);
			if ($result) {
				echo "删除成功! 3秒后条转回评论列表页";
				header("refresh:3;url='admin.php?c=comments&m=commentslist'");
			}
			else{
				echo "删除失败！";
				echo "<a href='admin.php?c=comments&m=commentslist'>返回列表</a>";
				
			}
		}
		function form(){
			$this->display();
		}
		function addcomments(){
			$data=$_POST;
			$file=$_FILES;
			$model=new CommentsModel();
			$result=$model->addComments($data,$file);
			if ($result) {
				echo "添加成功，3秒后返回评论列表";
				header("refresh:3;url='admin.php?c=comments&m=commentslist'");
			}else{
				echo "添加失败，3秒后返回添加页面重新注册";
				header("refresh:3;url='admin.php?c=comments&m=form'");
			}

		}
		function editcomments(){ //拿到数据给model层  得到数据给View层显示
			$cid=$_GET['id'];
			$model= new CommentsModel();
			$result=$model ->updateComments($cid);
			//var_dump($result);

			$this->assign('comments',$result);//送到view层显示数据
			$this->display();//送到view层显示数据
		}

		function updatecomments(){
			$data=$_POST;
			//var_dump($date);
			$file=$_FILES;
			$model=new CommentsModel();
			$result=$model->updateComments($data,$file);
			//var_dump($result);
			if ($result) {
				echo "修改成功! 3秒后条转回评论列表页";
				header("refresh:3;url='admin.php?c=comments&m=commentslist'");
			}
			else{
				echo "修改失败！";
				echo "<a href='admin.php?c=comments&m=commentslist'>返回列表</a>";
				
			}

		}
		
	}

 ?>

